package com.studyyoun.android.nonghe.person.activity;
/**
 * Created by zhaolong on 2017/10/16.
 * 站在顶峰，看世界
 * 落在谷底，思人生
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.studyyoun.android.androidcommonbaselibrary.activity.CommonBaseActivity;
import com.studyyoun.android.nonghe.R;
import com.studyyoun.android.nonghe.person.fragment.PersonCollectFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * class infation
 */
public class MyCollectActivity extends CommonBaseActivity {
    private View mBackLinearLayout;
    private TextView mHeaderTitleTextView;
    private ArrayList<String> mClumList;
    private TabLayout mTabLayout;
    private List<PersonCollectFragment> mCollectItemFragmentList = new ArrayList<>();
    private ViewPager mViewPager;

    @Override
    protected void getAllIntentExtraDatas(Intent intent) {

    }

    @Override
    protected int getCommonLayoutId() {
        return R.layout.activity_my_collect_layout;
    }

    @Override
    protected void commonInitView(View view) {
        mBackLinearLayout = findViewById(R.id.ll_base_back);
        mHeaderTitleTextView = findViewById(R.id.tv_base_header_title);
        mTabLayout = findViewById(R.id.tl_my_collect);

        mViewPager = findViewById(R.id.vp_my_collec_main);
    }

    @Override
    protected void commonFunction() {

    }

    @Override
    protected void commonDelayFunction() {
        mHeaderTitleTextView.setText("我的收藏");
        mBackLinearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mClumList = new ArrayList<>();
        mClumList.add("文章");
        mClumList.add("视频");
        mClumList.add("晨起一刻");


        for (String s : mClumList) {
            //标签
            mTabLayout.addTab(mTabLayout.newTab().setText(s));
            //页面
            PersonCollectFragment homeItemFragment = new PersonCollectFragment();
            Bundle bundle = new Bundle();
            bundle.putString("pageType", s);
            homeItemFragment.setArguments(bundle);
            mCollectItemFragmentList.add(homeItemFragment);

        }

        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public android.support.v4.app.Fragment getItem(int position) {
                return mCollectItemFragmentList.get(position);
            }

            @Override
            public int getCount() {
                return mCollectItemFragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mClumList.get(position);//页卡标题
            }
        });

        mTabLayout.setupWithViewPager(mViewPager);


        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                PersonCollectFragment personCollectFragment = mCollectItemFragmentList.get(position);
                personCollectFragment.loadingDatas();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        PersonCollectFragment personCollectFragment = mCollectItemFragmentList.get(0);
        personCollectFragment.loadingDatas();
    }
}
